let triangleNumber = function (nums) {
    const length = nums.length;
    let count = 0;
    if (nums == null || length < 3) return 0;
    nums.sort(function (a, b) { return a - b; });
    for (let k = length - 1; k >= 0; k--) {
        let i = 0, j = k - 1;
        while (i < j) {
            if (nums[i] + nums[j] >= nums[k]) {
                count += j - i;
            } else {
                i++;
            }
        }
    }
    return count;
}

